/**
 * Copyright © 2020 易久批信息技术有限公司. All rights reserved.
 */
package com.dysm.proxy.dynamic;


import org.springframework.cglib.proxy.Enhancer;

import java.lang.reflect.Proxy;

/**
 * 动态代理
 * @author xiay
 * @since 2020/12/10 10:13 下午
 */
public class DynamicProxyClient {

    public static void main(String[] args) {

        new Thread(() -> {
            RealStar xusong = new RealStar("许嵩");
            RealStarProxyHandler handler1 = new RealStarProxyHandler(xusong);
            Star star = (Star) Proxy.newProxyInstance(ClassLoader.getSystemClassLoader(), Star.class.getInterfaces(), handler1);
            star.sing();
        }, "许嵩").start();

        new Thread(() -> {
            RealStar libai = new RealStar("李白");
            RealStarProxyHandler handler2 = new RealStarProxyHandler(libai);
            Star star = (Star) Proxy.newProxyInstance(ClassLoader.getSystemClassLoader(), new Class[]{Star.class}, handler2);
            star.sing();
        }, "李白").start();

        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(UnknownStar.class);
        enhancer.setCallback(new MyMethodInterceptor());
        Star star = (Star)enhancer.create();
        star.sing();

    }
}
